class Admin::StudentsController < ApplicationController
  def new
    @page_title = 'Create new student'
    @student = Student.new  
  end

  def create
    @student = Student.new(params[:student])
    if @student.save
      flash[:notice] = "Student #{@student.name} was successfully created."
    redirect_to :action => 'index'
    else
      @page_title = 'Create new student'
      render :action => 'new'
    end
  end

  def edit
    @student = Student.find(params[:id])
    @page_title = 'Edit student'
  end

  def update
    @student = Student.find(params[:id])
    if @student.update_attributes(params[:student])
      flash[:notice] = "student #{@student.name} was successfully updated."
    redirect_to :action => 'show', :id => @student.id
    else
      @page_title = 'Edit student'
      render :action => 'edit'
    end
  end

  def destroy
    @student = Student.find(params[:id])
    flash[:notice] = "Successfully deleted student #{@student.name}"
    @student.destroy
    redirect_to :action => 'index'
  end

  def show
    @student = Student.find(params[:id])
    @page_title = @student.name
  end

  def index
    @students = Student.find(:all)
    @page_title = 'Listing students'
  end

end
